﻿import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'ring_info_logic.dart';
import '../routes.dart';

/// 戒指信息页面
class RingInfoView extends GetView<RingInfoLogic> {
  const RingInfoView({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor:  Colors.black,
      appBar: AppBar(
        backgroundColor: const Color(0xFF282528),
        elevation: 0,
        leading: GestureDetector(
          onTap: () => Get.back(),
          child: const Icon(
            Icons.arrow_back_ios,
            color: Colors.white,
            size: 20,
          ),
        ),
        title: const Text(
          '戒指信息',
          style: TextStyle(
            color: Colors.white,
            fontSize: 18,
            fontWeight: FontWeight.w500,
          ),
        ),
        centerTitle: true,
      ),
      body: SingleChildScrollView(
        padding: EdgeInsets.all(24.w),
        child: Column(
          children: [
            Container(
              decoration: BoxDecoration(
                color: const Color(0xFF282528),
                borderRadius: BorderRadius.circular(28.r),
              ),
              child: Column(
                children: [
                  _buildListItem('固件信息',
                      () => Get.toNamed(SettingsRoutes.firmware)),
                  _buildDivider(),
                  _buildListItem('恢复出厂', () => _showFactoryResetDialog()),
                  _buildDivider(),
                  _buildListItem('固件升级', () => Toast.show('固件升级功能即将推出')),
                  _buildDivider(),
                  _buildListItem('保修状态',
                      () => Get.toNamed(SettingsRoutes.warranty)),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildListItem(String title, VoidCallback onTap) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        height: 50.h,
        padding: EdgeInsets.symmetric(horizontal: 20.w),
        child: Row(
          children: [
            Expanded(
              child: Text(
                title,
                style: TextStyle(
                  color: Colors.white,
                  fontSize: 16.sp,
                ),
              ),
            ),
            const Icon(
              Icons.arrow_forward_ios,
              color: Color(0xFF666666),
              size: 16,
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildDivider() {
    return Divider(
      height: 1,
      thickness: 1,
      color: const Color(0xFF1A1A1A),
      indent: 20.w,
      endIndent: 20.w,
    );
  }

  /// 显示恢复出厂设置确认对话框
  void _showFactoryResetDialog() {
    Get.dialog(
      AlertDialog(
        backgroundColor: const Color(0xFF282528),
        title: const Text('恢复出厂设置', style: TextStyle(color: Colors.white)),
        content: const Text(
          '恢复出厂设置将清除所有数据，确定要继续吗？',
          style: TextStyle(color: Colors.white),
        ),
        actions: [
          TextButton(
            onPressed: () => Get.back(),
            child: const Text('取消', style: TextStyle(color: Colors.white)),
          ),
          TextButton(
            onPressed: () {
              Get.back();
              // TODO: 执行恢复出厂设置
              Toast.show('恢复出厂设置功能即将推出');
            },
            child: const Text('确定', style: TextStyle(color: Color(0xFFFF6B6B))),
          ),
        ],
      ),
    );
  }
}
